
package com.yidin.util;

import android.content.Context;
import android.graphics.Color;
import android.view.Gravity;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

/**
 * 显示异步旋转动画
 * @author cola
 * @since 20120716
 */
public class loading extends LinearLayout{
	private Button loadbtn;
	private LinearLayout load;
	private Context context;
	public loading(Context context,int anim,int icon) {
		super(context);
		// TODO Auto-generated constructor stub
		this.context = context;
		this.addView(this.createLoading(anim,icon));
	}

	public View createLoading(int anim,int icon) {
		TextView tv = new TextView(this.context);
		LinearLayout.LayoutParams lp;
		lp = new LinearLayout.LayoutParams(-1, -2);
		RelativeLayout.LayoutParams mParams = new RelativeLayout.LayoutParams(
				32,//
				32);
		mParams.addRule(RelativeLayout.CENTER_IN_PARENT);

	    Animation an ;
	    an = AnimationUtils.loadAnimation(this.context, anim);
		//AnimationDrawable rocketAnimation;
		this.load = new LinearLayout(this.context);
		this.loadbtn = new Button(this.context);
		this.loadbtn.setLayoutParams(mParams);
		this.loadbtn.setGravity(Gravity.CENTER);
		
		this.loadbtn.setBackgroundResource(icon);
		this.loadbtn.startAnimation(an);
		//rocketAnimation = (AnimationDrawable) this.loadbtn.getBackground();
		//rocketAnimation.start();
		//this.loadbtn.setTextAppearance(this.context, R.style.progressStyle);
		this.load.setGravity(Gravity.CENTER);
		tv.setTextSize(15f);
		tv.setText("正在加载，请稍候...");
		tv.setTextColor(Color.rgb(100, 100, 100));
		mParams = new RelativeLayout.LayoutParams(
				RelativeLayout.LayoutParams.WRAP_CONTENT,//
				RelativeLayout.LayoutParams.WRAP_CONTENT);
		tv.setLayoutParams(mParams);
		this.load.setLayoutParams(lp);
		this.load.addView(loadbtn);
		this.load.addView(tv);
		return load;
	}
}
